<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
</head>
<body>
<div id="app">
<input type="text" v-model="n1">
<input type="text" v-model="n2">
<input type="button" value="加" @click="f('+')">
<input type="button" value="减" @click="f('-')">
<input type="button" value="乘" @click="f('*')">
<input type="button" value="除" @click="f('/')">
<hr>
    <h1>结果:{{result}}</h1>
</div>
<script src="js/vue.min.js"></script>
<script>
  let v=new Vue({
    el: "#app",
    data: {
      result:"",
        n1:"",
        n2:""
    },
    methods: {
      f(x){
        if (isNaN(v.n1)||isNaN(v.n2)){
          d.innerText = "输入错误!";
          return;
        }
  //5   +   2   "5+2"  eval()方法可以将字符串以js代码的形式运行
        v.result=eval(v.n1+x+v.n2);
      }
    }
  })
</script>
</body>
</html>